package com.yc.class_attendance.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yc.class_attendance.R;
import com.yc.class_attendance.entity.PersonnelResutl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by PC on 2017/4/11.
 */

public class AttendanceAdapter extends BaseAdapter {
    Context context;
    List<PersonnelResutl> list = new ArrayList<>();
    int j=0;

    public AttendanceAdapter(Context context) {
        this.context = context;

    }
    public AttendanceAdapter(Context context , List<PersonnelResutl> list) {
        this.context = context;
        this.list =list;

    }
    public void setDate(List<PersonnelResutl> list ) {
        this.list.addAll(list);
        notifyDataSetChanged();
    }
    public  void   clear(){
        this.list.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;

        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_attendance, null);
            viewHolder.textView = (TextView) view.findViewById(R.id.te);
            viewHolder.textView1 = (TextView) view.findViewById(R.id.text1);

            viewHolder.iv_type = (ImageView) view.findViewById(R.id.iv_type);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        if (list.get(i).getXm().length()==2){
            viewHolder.textView.setText(list.get(i).getXm()+"        ");
        }else if(list.get(i).getXm().length()==3) {
            viewHolder.textView.setText(list.get(i).getXm()+"     ");
        }else {
            viewHolder.textView.setText(list.get(i).getXm());
        }
        viewHolder.textView1.setText(list.get(i).getTime());

        Log.d("TAG","list:"+list.get(i).getType());

        if (list .get(i).getType() == 0) {
            viewHolder.iv_type.setImageResource(R.mipmap.index__weixuanzhongyishuaka_icon_one);
        } else if(list .get(i).getType() == 1) {
            viewHolder.iv_type.setImageResource(R.mipmap.index__xuanzhongyishuaka_icon_one);
            viewHolder.textView.setTextColor(Color.parseColor("#9d2824"));
            viewHolder.textView1.setTextColor(Color.parseColor("#9d2824"));

        }else if(list .get(i).getType() == 2) {
            viewHolder.iv_type.setImageResource(R.mipmap.index__xuanzhongyishuaka_icon_no_tui);
            viewHolder.textView.setTextColor(Color.parseColor("#c4110c"));
            viewHolder.textView1.setTextColor(Color.parseColor("#c4110c"));

        }

        return view;
    }

    public final class ViewHolder {
        TextView textView;
        TextView textView1;
        ImageView iv_type;
    }
}
